//
//  PublishedNewsFlashModel.m
//  Btpin
//
//  Created by Vic on 2019/12/17.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "PublishedNewsFlashModel.h"

@implementation PublishedNewsFlashModel

- (void)setValuesForKeysWithDictionary:(NSDictionary<NSString *,id> *)keyedValues {
    self.id = [UIToolsControl dataAnalysis:keyedValues[@"id"]];
    self.title = [UIToolsControl dataAnalysis:keyedValues[@"title"]];
    self.desc = [UIToolsControl dataAnalysis:keyedValues[@"desc"]];
    self.url = [UIToolsControl dataAnalysis:keyedValues[@"url"]];
    self.time = [UIToolsControl dataAnalysis:keyedValues[@"time"]];
    self.audit = [UIToolsControl dataAnalysis:keyedValues[@"audit"]];
    self.audit_mark = [UIToolsControl dataAnalysis:keyedValues[@"audit_mark"]];
    
    self.typeID = [UIToolsControl dataAnalysis:keyedValues[@"typeid"]];
    
    self.thumb = [UIToolsControl dataAnalysis:keyedValues[@"thumb"]];
    self.add_time = [UIToolsControl dataAnalysis:keyedValues[@"add_time"]];
    self.add_timeShow = @"";
    if (self.add_time && self.add_time.length) {
        long minute = 60; // 1分
        long hour = 60 * minute; // 1小时
        long day = 24 * hour; // 1天
        long month = 3 * day; // 3天
//        long year = 12 * month; // 1年
        
        long diff = [[UIToolsControl getCurrentTimestamp] integerValue] - [self.add_time integerValue];
        NSInteger r = 0;
        if (diff > month) {
            self.add_timeShow = [UIToolsControl timestampConversionTime:([self.add_time integerValue]) andFormat:@"yyyy-MM-dd"];
        } else if (diff > day) {
            r = (diff / day);
            self.add_timeShow = [NSString stringWithFormat:@"%ld天前", (long)r];
        } else if (diff > hour) {
            r = (diff / hour);
            self.add_timeShow = [NSString stringWithFormat:@"%ld个小时前", (long)r];
        } else if (diff > minute) {
            r = (diff / minute);
            self.add_timeShow = [NSString stringWithFormat:@"%ld分钟前", (long)r];
        } else {
            self.add_timeShow = [NSString stringWithFormat:@"%ld秒前", (long)r];
        }
    }
    
    self.titleHeight = ScalePS(30);
    self.cellHeight = ScalePS(110);
    if (self.title && self.title.length) {
        self.titleHeight = [UIToolsControl textHeightWithLineSpacing:self.title size:CGSizeMake(WIDTH-ScalePS(50), MAXFLOAT) boldFont:Font_16];
        self.cellHeight += self.titleHeight;
    }
    
    self.titleHeightForNews = ScalePS(30);
    self.cellHeightForNews = ScalePS(110);
    if (self.title && self.title.length) {
        self.titleHeightForNews = [UIToolsControl textHeightWithLineSpacing:self.title size:CGSizeMake(ScalePS(210), MAXFLOAT) boldFont:Font_16];
        self.cellHeightForNews += self.titleHeight;
    }
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

- (id)copyWithZone:(NSZone *)zone {
    PublishedNewsFlashModel *model = [[[self class] allocWithZone:zone] init];
    model.id = self.id;
    model.title = self.title;
    model.desc = self.desc;
    model.url = self.url;
    model.time = self.time;
    model.audit = self.audit;
    model.audit_mark = self.audit_mark;
    model.typeID = self.typeID;
    model.thumb = self.thumb;
    model.add_time = self.add_time;
    model.add_timeShow = self.add_timeShow;
    model.titleHeight = self.titleHeight;
    model.cellHeight = self.cellHeight;
    model.titleHeightForNews = self.titleHeightForNews;
    model.cellHeightForNews = self.cellHeightForNews;
    
    return model;
}

@end
